package com.ysj.demo.accompanynetwork.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.widget.TextView;

import com.ysj.demo.accompanynetwork.R;
import com.ysj.demo.accompanynetwork.util.StatusBarUtil;
import com.ysj.demo.accompanynetwork.adapter.PublishTabFragmentPagerAdapter;
import com.ysj.demo.accompanynetwork.fragment.AllPublishFragment;

import java.util.ArrayList;
import java.util.List;

public class IIssuedInformationActivity extends BaseActivity {
    private TextView titleTv;
    private TabLayout tabl;
    private AllPublishFragment allFl;
    private AllPublishFragment partFl;
    private AllPublishFragment partF2;
    private ViewPager pager;
    private PublishTabFragmentPagerAdapter adapter;
    private List<Fragment> list;
    private FragmentManager manager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_iissued_information);
        StatusBarUtil.fullScreen(this);
        initView();
    }

    private void initView() {
        titleTv = findViewById(R.id.top_tv);
        titleTv.setText("我发布的信息");
        tabl = findViewById(R.id.tab_layout);
        pager = findViewById(R.id.view_pager);

        allFl = new AllPublishFragment();
        partFl = new AllPublishFragment();
        partF2 = new AllPublishFragment();
        list = new ArrayList<>();
        list.add(allFl);
        list.add(partFl);
        list.add(partF2);
        manager = getSupportFragmentManager();
        adapter = new PublishTabFragmentPagerAdapter(manager, list);

        ArrayList<String> mList = new ArrayList<>();
        mList.add("全部");
        mList.add("已找到玩伴");
        mList.add("未找到玩伴");

        pager.setAdapter(new MyAdapter(getSupportFragmentManager(), mList));
        /*Tab与ViewPager绑定*/
        tabl.setupWithViewPager(pager);



    }

    public class MyAdapter extends FragmentPagerAdapter {

        private List<String> mlist;

        public MyAdapter(FragmentManager fm, List<String> list) {
            super(fm);
            this.mlist = list;
        }

        @Override
        public Fragment getItem(int position) {
            return list.get(position);
        }

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mlist.get(position);
        }
    }
}
